/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package testeinterface;

/**
 *
 * @author ra120212
 */

import java.io.FileWriter; 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Locale;

public class Logger {
    
    private static FileWriter arq;
    private static PrintWriter gravarArq;
  
    public static final int INICIALIZANDO_METODO = 0;
    public static final int FINALIZANDO_METODO = 1;
    public static final int ERRO = 2;
    
    public static final String[] MENSAGENS_STATUS = {"Inicializando método ",
                                                 "Finalizando método ", "Erro no método "};
  
  private static String getHora(){
      
    Locale locale = new Locale("pt","BR"); 
    GregorianCalendar calendar = new GregorianCalendar(); 
    SimpleDateFormat formatador = new SimpleDateFormat("dd'/'MM'/'yyyy' - 'HH':'mm':'ss ",locale); 
    return formatador.format(calendar.getTime());
    
  }
  private static void gravarArquivo(String s){
      try{  
        arq = new FileWriter("Pudim.txt", true);
        gravarArq = new PrintWriter(arq);
        gravarArq.printf(getHora() + s +"\n");       
        arq.close();
    }
    catch(IOException e){
        System.err.println(e.getMessage());
    }
      
  }
  
  public static void gravar(int status, String nomeMetodo){
      gravarArquivo(MENSAGENS_STATUS[status] + nomeMetodo);
  }
  
  public static void gravar(String mensagem){    
      gravarArquivo(mensagem);
      
  }
    
}
